package com.guocheng.entity;

import java.util.HashMap;

public class AjaxResult extends HashMap<String,Object> {

    public AjaxResult(ResultHttpStatus resultHttpStatus){
        put("code",resultHttpStatus.getCode());
        put("msg",resultHttpStatus.getMsg());
        put("success",resultHttpStatus.getSuccess());
    }

    public static AjaxResult ok(){
        return new AjaxResult(ResultHttpStatus.OK);
    }

    public static AjaxResult ok(String msg){
        AjaxResult ajaxResult = new AjaxResult(ResultHttpStatus.OK);
        ajaxResult.put("msg",msg);
        return ajaxResult;
    }

    public static AjaxResult error(){
        return new AjaxResult(ResultHttpStatus.ERROR);
    }

    public static AjaxResult error(String msg){
        AjaxResult resultMap = new AjaxResult(ResultHttpStatus.ERROR);
        resultMap.put("msg",msg);
        return resultMap;
    }

    public AjaxResult data(Object data){
        put("data",data);
        return this;
    }

    public AjaxResult total(long total){
        put("total",total);
        return this;
    }

    @Override
    public AjaxResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
